public class demo6 {
    public static void main(String[] args) {
        Thread t=new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("线程工作中");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //1、假装没听见，循环继续执行，线程就不结束了
                    e.printStackTrace();
                    //2、加上break表示让线程立即结束
                    break;
                    //3、再在这里做一些其他工作后，再执行break
                }
            }
        });
        t.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("让t线程终止");
        t.interrupt();
    }
}
